﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            //float remaining =100;
            //try
            //{

            //    Console.WriteLine("1、存款，2、取款，3、退出");
            //    int q = int.Parse(Console.ReadLine());
            //    float a;
            //    switch (q)
            //    {
            //        case 1:
            //            Console.WriteLine("请输入你要存款金额");
            //            a = float.Parse(Console.ReadLine());
            //            remaining = remaining + a;
            //            break;
            //        case 2:
            //            Console.WriteLine("请输入你要取款金额");
            //            a = float.Parse(Console.ReadLine());
            //            if (a > remaining)
            //            {
            //                throw new ArgumentOutOfRangeException("取款金额大于余额，请重新输入");
            //            }
            //            remaining = remaining - a;
            //            break;
            //        case 3:

            //            break;
            //        default:
            //            break;
            //    }
            //}
            //catch (ArgumentOutOfRangeException e)
            //{
            //    Console.WriteLine(e.Message);
            //    Console.WriteLine(e.Source);

            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.Message);
            //    Console.WriteLine(e.Source);

            //}
            //Console.WriteLine("余额"+ remaining);
            float remaining = 100;
            t(remaining);
        }
        static void t(float remaining)
        {
            
            try
            {

                Console.WriteLine("1、存款，2、取款，3、退出");
                int q = int.Parse(Console.ReadLine());
                float a;
                switch (q)
                {
                    case 1:
                        Console.WriteLine("请输入你要存款金额");
                        a = float.Parse(Console.ReadLine());
                        remaining = remaining + a;
                        
                        break;
                    case 2:
                        Console.WriteLine("请输入你要取款金额");
                        a = float.Parse(Console.ReadLine());
                        if (a > remaining)
                        {
                            throw new ArgumentOutOfRangeException("取款金额大于余额，请重新输入");
                        }
                        remaining = remaining - a;
                        
                        break;
                    case 3:

                        break;
                    default:
                        break;
                }
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);

            }
            Console.WriteLine("余额" + remaining);
            t(remaining);

        }
    }
}
